package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.entity.Result;
import com.atguigu.pojo.Address;
import com.atguigu.service.AddressService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * AddressController
 *
 * @Author: 马伟奇
 * @CreateTime: 2021-02-19
 * @Description:
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Reference
    private AddressService addressService;


    @RequestMapping("/findAllMaps")
    public Map findAllMaps(){
      Map map = new HashMap<>();
        // 查询所有分公司的地址
      List<Address> addressList =  addressService.findAll();

      // 存放经纬度
        List<Map> gridnMaps = new ArrayList<>();

        // 存放分公司名字
        List<Map> addressName = new ArrayList<>();
        //    for(var x=0;x<data.gridnMaps.length;x++){
//        adds.push(new BMap.Point(data.gridnMaps[x].lng,data.gridnMaps[x].lat));
//        addNames.push(data.nameMaps[x].addressName);
//    }

        for (Address address : addressList) {
            Map gridnMap = new HashMap<>();
            gridnMap.put("lng",address.getLng());
            gridnMap.put("lat",address.getLat());
            gridnMaps.add(gridnMap);

            Map addressNameMap = new HashMap<>();
            addressNameMap.put("addressName",address.getAddressName());
            addressName.add(addressNameMap);

        }

        map.put("gridnMaps",gridnMaps);
        map.put("nameMaps",addressName);
        return map;



    }
}